package com.xxx.hhh.demo.demo6;

import java.io.*;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.function.Predicate;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
//        创建对象
        ServerSocket ss = new ServerSocket(10000);
//        监听数据
        Socket s = ss.accept();
//        获取流对象
        InputStream inputStream = s.getInputStream();
//        将流对象转为字符流
        BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
//        获取客户端IP
        InetAddress inetAddress = s.getInetAddress();
//        获取字符流信息并打印
        String s1 = br.readLine();
        String hostAddress = inetAddress.getHostAddress();
        System.out.println(hostAddress);
        System.out.println(s1);
//        输出数据
        OutputStream os = s.getOutputStream();
       BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
       bw.write("我是你爹");
       bw.newLine();
       bw.flush();


        ss.close();
    }
}
